Skip to content

Fix array casts as string #3418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from

Conversation

hans-thomas
Copy link
Contributor

Hello everyone :)
As described here #3306, when casting an array attribute as array, it will save as a JSON-encoded string.
In this PR, I prevent casting an array to a string.

@hans-thomas hans-thomas requested a review from a team as a code owner June 29, 2025 12:08
@hans-thomas hans-thomas requested a review from paulinevos June 29, 2025 12:08
@hans-thomas
Copy link
Contributor Author

Hi @paulinevos, could you please review my PR?

@alcaeus alcaeus requested review from alcaeus and removed request for paulinevos July 23, 2025 07:52
@alcaeus
Copy link
Member

alcaeus commented Jul 23, 2025

@hans-thomas in general, the changes look good. I am a little bit worried about the BC impact of this change, as any fields that previously used an array cast will have been saved as JSON string and won't be read successfully in future. To mitigate this, we need to do two things:

  • Create a new json cast that people should use instead of array (ignore if something like that already exists in Laravel)
  • Emit a deprecation notice in isJsonCastable if someone is using an array cast. If they are, we should tell them to either use the json cast if they want to store the array as a JSON-encoded string, or to remove the array cast if they want to store it as an array. We can then remove that deprecation notice in the next major version.

With the _id vs. id issue fresh in my mind, I don't want to create another data migration problem for users, so we need to give people the option to retain the old behaviour, no matter how useless it may be in MongoDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants